% by ylx sby 6/11
% Version 5.0
% Based on SBY's fQR.m
% calculating profit
function [profit] = function_fQR2(Q,R,n)
	global I ci cI r % 主程序中定义
	Q_new = Q;
	R_new = R;
	for nn=1:n+1
		Q_new(:, nn) = r * (nn - 1) * Q_new(:, nn);
		R_new(:, nn) = (nn - 1) * R_new(:, nn);
    end
		R_new = ci * R_new;
		R_new(I, :) = (cI + ci) / ci * R_new(I, :);
	    profit = sum(sum(Q_new(:,1:n+1)))-sum(sum(R_new(:,1:n+1)));     
	return;